Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add Module.print_hierarchy #281

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shareefj
Copy link

@shareefj shareefj commented Nov 8, 2023

Adding a new Module method that prints the hierarchy. Useful for visualising the structure of a module.

I'm adding this PR mainly to start a conversation about where is best to do this sort of thing. I'd like to be able to pretty print some sort of hierarchy view of a design. It would be nice to be able to do something similar to how tree prints directory hierarchies but I haven't looked further that the simple indentation shown in this PR.

Should this go in the Module class or in the verilog module or in some new module?

continue
name = "anon"
print("{}{}:{}".format(" " * indent, name, submodule.__class__.__name__))
self._iter_submodules(submodule, indent=indent+4)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call print_hierarchy instead and merge the two functions?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed _iter_submodules.

@shareefj
Copy link
Author

shareefj commented Nov 8, 2023

There do seem to be some nice options for pretty printing this but I'll leave that for another day. This simple indentation works for now I think. https://stackoverflow.com/questions/9727673/list-directory-tree-structure-in-python

continue
name = "anon"
print("{}{}:{}".format(" " * indent, name, submodule.__class__.__name__))
self.print_hierarchy(submodule, indent+4, include_anon)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just submodule.print_hierarchy and remove the module argument?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I see what you're getting at.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a fix that I think did what you wanted. Each submodule is called in turn and we call the submodule.print_hierarchy(indent+4, include_anon).

Adding a new Module method that prints the hierarchy. Useful for visualising
the structure of a module.
@shareefj
Copy link
Author

@sbourdeauducq Did the last push do what you were implying?

@sbourdeauducq
Copy link
Member

It's better, there is still an issue with indent handling, just do the *4 multiplication at print time.

@shareefj
Copy link
Author

Not sure what you mean. The multiplication is done at print time. Did you mean something else?

        if indent == 4:
            print(self.__class__.__name__)
        for name, submodule in self._submodules:
            if name is None:
                if not include_anon:
                    # all hierarchy below an anonymous module is skipped
                    continue
                name = "anon"
            print("{}{}:{}".format(" " * indent, name, submodule.__class__.__name__))
            submodule.print_hierarchy(indent+4, include_anon)

@sbourdeauducq
Copy link
Member

The 4

@shareefj
Copy link
Author

shareefj commented Dec 1, 2023

++verbosity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants